<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.key" placeholder="委托人名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"  @click="getDataList()">本地查询</el-button>
        <el-button v-if="isAuth('bdc:bdcproxyinfo:save')" type="primary" @click="addOrUpdateHandle()">生成委托书</el-button>

      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">




      <el-table-column
        prop="name"
        header-align="center"
        align="center"
        width="110px"
        label="委托人名称">
      </el-table-column>

      <el-table-column
        prop="ptype"
        header-align="center"
        align="center"
        width="110px"
        label="委托人类型">
      </el-table-column>


      <el-table-column
        prop="idcode"
        header-align="center"
        align="center"
        width="160px"
        label="委托人证件号码">
      </el-table-column>

            <el-table-column
        prop="dealtime"
        header-align="center"
        align="center"
        width="160px"
        label="备案时间">
      </el-table-column>

      <el-table-column
        prop="stateTranslate"
        header-align="center"
        align="center"
        label="状态">
      </el-table-column>

      <el-table-column
        prop="ctype"
        header-align="center"
        align="center"
        width="110px"
        label="委托书类型">
      </el-table-column>

      <el-table-column
        prop="realtyunitno"
        header-align="center"
        align="center"
        width="160px"
        label="不动产单元号">
      </el-table-column>
      <el-table-column
        prop="realtycertno"
        header-align="center"
        align="center"
          width="160px"
        label="不动产权证号">
      </el-table-column>
      <el-table-column
        prop="realtyno"
        header-align="center"
        align="center"
        width="160px"
        label="不动产登记证明号">
      </el-table-column>
      <el-table-column
        prop="proxyno"
        header-align="center"
        align="center"
        width="190px"
        label="委托书编号">
      </el-table-column>
      <el-table-column
        prop="enabledate"
        header-align="center"
        align="center"
        width="120px"
        label="有效开始时间">
      </el-table-column>
      <el-table-column
        prop="disabledate"
        header-align="center"
        align="center"
        width="120px"
        label="有效结束时间">
      </el-table-column>


      <el-table-column
        fixed="left"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" v-if="scope.row.state=='0' && isAuth('bdc:bdcproxyinfo:save')" @click="addOrUpdateHandle(scope.row.seqno)">修改备案信息</el-button>
          <el-button type="text" size="small" v-if="scope.row.state=='0' && isAuth('bdc:bdcproxyinfo:save')" @click="uploadHandle(scope.row.seqno)">上传备案</el-button>
          <el-button type="text" size="small" v-if="scope.row.state=='0' && isAuth('bdc:bdcproxyinfo:save')" @click="downApply(scope.row.seqno)">下载委托书</el-button>
          <el-button type="text" size="small" v-if="scope.row.ctype=='B'"
            @click="ndyQueryHandle(scope.row.region, scope.row.proxyno,scope.row.name,scope.row.idcode,scope.row.realtyunitno,scope.row.realtycertno)">拟抵押查询</el-button>
                    <el-button type="text" size="small" v-if="scope.row.ctype=='B'"
            @click="houseQueryHandle(scope.row.region, scope.row.proxyno,scope.row.name,scope.row.idcode)">购房情况查询</el-button>  
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="datepicker.pageOptions"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <bdc-realtyunit-proxy v-if="bdcRealtyunitProxyVisible" ref="bdcRealtyunitProxy" @refreshDataList="getDataList"></bdc-realtyunit-proxy>
    <bdc-purchase-proxy v-if="bdcPurchaseProxyVisible" ref="bdcPurchaseProxy" @refreshDataList="getDataList"></bdc-purchase-proxy>
    <bdc-proxy-upload v-if="bdcProxyUploadVisible" ref="bdcProxyUpload" @refreshDataList="getDataList"></bdc-proxy-upload>
  </div>
</template>

<script>
  import AddOrUpdate from './bdcproxyinfo-add-or-update'
  import BdcRealtyunitProxy from './bdc-realtyunit-proxy'
  import BdcPurchaseProxy from './bdc-purchase-proxy'
  import BdcProxyUpload from './bdcproxyinfo-upload'
  export default {
    data () {
      return {
        dataForm: {
          key: ''
        },
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,
        bdcRealtyunitProxyVisible: false,
        bdcPurchaseProxyVisible: false,
        bdcProxyUploadVisible: false
      }
    },
    components: {
      AddOrUpdate,
      BdcRealtyunitProxy,
      BdcPurchaseProxy,
      BdcProxyUpload
    },
    activated () {
     
        this.getDataList()
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/bdc/bdcproxyinfo/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
     
      downApply(id){
          var token = this.$cookie.get('token')
      　　var url = this.$http.adornUrl('/bdc/bdcproxyinfo/downApply/' + id + '?token=' + token)
          window.location.href = url
      },
      uploadHandle (id) {
        this.bdcProxyUploadVisible = true
        this.$nextTick(() => {
          this.$refs.bdcProxyUpload.init(id)
        })
      },
      ndyQueryHandle(region, proxyno, name, idcode, realtyunitno, realtycertno) {
        this.bdcRealtyunitProxyVisible = true
        this.$nextTick(() => {
          this.$refs.bdcRealtyunitProxy.init(region, proxyno, name, idcode, realtyunitno, realtycertno)
        })
      },
      houseQueryHandle(region, proxyno, name, idcode) {
        this.bdcPurchaseProxyVisible = true
        this.$nextTick(() => {
          this.$refs.bdcPurchaseProxy.init(region, proxyno, name, idcode)
        })
      },
      // 删除
      deleteHandle (id) {
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.seqno
        })
        this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/bdc/bdcproxyinfo/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      }
    }
  }
</script>
<style lang="scss">
body .el-table th.gutter{
    display: table-cell!important;

}
.el-input-number .el-input__inner{
  -webkit-appearance: none;
  padding-left: 50px;
  padding-right: 50px;
  text-align: left;
}
</style>